home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / anubis / pcx256.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-04  |  4.7 KB  |  206 lines

  1. // PCX
  2. // (C) Anubis Software, Junio 1995
  3. #ifndef PCX
  4. #define PCX
  5.  
  6. // --------------------------------------+
  7. // Inclusión de librerías estandares     |
  8. // --------------------------------------+
  9. #include <stdio.h>
  10. #include <alloc.h>
  11.  
  12. // --------------------------------------+
  13. // Inclusion de librerias Anubis Soft    |
  14. // --------------------------------------+
  15. #include "mdefs.h"
  16. #include "grafic1.h"
  17.  
  18. // --------------------------------------+
  19. // Definición de los tipos de datos      |
  20. // --------------------------------------+
  21. typedef struct {
  22.    BYTE Fabricante;        // El fabricante 10=ZSoft.PCX
  23.    BYTE Version;           // (0..5)
  24.    BYTE Codificacion;      // (1) Run Length
  25.    BYTE BitsPixel;         // (1,2,4,8) Número de colores.
  26.    WORD Xmin;
  27.    WORD Ymin;
  28.    WORD Xmax;
  29.    WORD Ymax;
  30.    WORD HDpi;
  31.    WORD VDpi;
  32.    BYTE Color[48];
  33.    BYTE Res;               // =0
  34.    BYTE NPlanes;
  35.    WORD BytesLine;
  36.    WORD PaletteInfo;
  37.    WORD HscreenSize;
  38.    WORD VscreenSize;
  39.    BYTE Relleno[54];
  40. } PCXCab;
  41.  
  42. typedef struct {
  43.    PCXCab Cabecera;
  44.    PBYTE  *Datos;
  45.    PBYTE  *Paleta;
  46. } pcx256;
  47.  
  48. // ------------------------------------+
  49. // Declaración de variables globales   |
  50. // ------------------------------------+
  51.  
  52. // ------------------------------------+
  53. // Declaración de prototipos de la lib |
  54. // ------------------------------------+
  55. boolean LeePCX (pcx256 *, char *);
  56. void PonPCX(pcx256 *, int, int);
  57. void PonmaskPCX(pcx256 *, int, int, BYTE);
  58. boolean PonfPCX(char *, int, int);
  59.  
  60. // ------------------------------------+
  61. // Implementacion de los prototipos    |
  62. // ------------------------------------+
  63. boolean LeePCX (pcx256 *imagen, char *fichero)
  64. {
  65.    FILE *fp;
  66.    int fin;
  67.  
  68.    if((fp=fopen(fichero,"rb"))!=NULL)  {
  69.       fread(&((*imagen).Cabecera),sizeof(PCXCab),1,fp);
  70.       if((*imagen).Cabecera.BitsPixel == 8)  {
  71.     fseek(fp,-768,SEEK_END);
  72.     (*imagen).Paleta = malloc(768);
  73.     fread( (*imagen).Paleta, 768, 1, fp);
  74.     fin=ftell(fp);
  75.     (*imagen).Datos = malloc(fin);
  76.     rewind(fp);
  77.     fseek(fp,128,0);
  78.     fread( (*imagen).Datos, fin, 1, fp);
  79.       }// end if
  80.       return(TRUE);
  81.    }  else  {
  82.       return(FALSE);
  83.    }// end if
  84. }// end LeePCX
  85.  
  86.  
  87. void PonPCX (pcx256 *imagen,int Xini,int Yini)
  88. {
  89.    int ancho=(*imagen).Cabecera.Xmax - (*imagen).Cabecera.Xmin;
  90.    int alto =(*imagen).Cabecera.Ymax - (*imagen).Cabecera.Ymin;
  91.    PBYTE ch =(PBYTE) (*imagen).Datos;
  92.    BYTE rep;
  93.    int x=0,y=0,con;
  94.  
  95.    while( (x<ancho) || (y<alto))  {
  96.       if ( (*ch & 192) == 192)  {
  97.          rep= *ch & 63;
  98.          ch++;
  99.       }// end if
  100.       for( con=0;con<rep;con++)  {
  101.          ActPunto (Xini+x,Yini+y,*ch);
  102.          x++;
  103.          if(x>ancho)  {
  104.             x=0;
  105.             y++;
  106.      }// end if
  107.       }// end for
  108.       rep=1;
  109.       ch++;
  110.    }// end while
  111. }// end PonPCX
  112.  
  113. void PonmaskPCX (pcx256 *imagen,int Xini,int Yini,BYTE mask)
  114. {
  115.    int ancho=(*imagen).Cabecera.Xmax - (*imagen).Cabecera.Xmin;
  116.    int alto =(*imagen).Cabecera.Ymax - (*imagen).Cabecera.Ymin;
  117.    PBYTE ch =(PBYTE) (*imagen).Datos;
  118.    BYTE rep;
  119.    int x=0,y=0,con;
  120.  
  121.    while( (x<ancho) || (y<alto))  {
  122.       if ( (*ch & 192) == 192)  {
  123.          rep= *ch & 63;
  124.          ch++;
  125.       }// end if
  126.       for( con=0;con<rep;con++)  {
  127.          if (*ch != mask)  
  128.             ActPunto (Xini+x,Yini+y,*ch);
  129.          x++;
  130.      if(x>ancho)  {
  131.         x=0;
  132.             y++;
  133.          }// end if
  134.       }// end for
  135.       rep=1;
  136.       ch++;
  137.    }// end while
  138. }// end PonmaskPCX
  139.  
  140. boolean PonfPCX(char *fichero, int Xini, int Yini)
  141. {
  142.    int x1, x2, y1, y2, x, y;
  143.    char dato[2000];
  144.    register int zx,zy;
  145.    char rep=1;
  146.    char con;
  147.    char ch;
  148.    FILE *fp;
  149.  
  150.    if( (fp=fopen(fichero,"rb"))==NULL)  return(FALSE);
  151.    fseek(fp,4,0);
  152.    x1=getw(fp);
  153.    y1=getw(fp);
  154.    x2=getw(fp);
  155.    y2=getw(fp);
  156.    x=x2-x1;
  157.    y=y2-y1; 
  158.    fseek(fp,128,0);
  159.    zx=0,zy=0;
  160.    while(feof(fp)==0)  {
  161.       ch=getc(fp);
  162.       if (feof(fp) != 0)  goto end;
  163.       if((ch&192)==192)  {
  164.          rep=(ch&63);
  165.          ch=getc(fp);
  166.       }// end if
  167.       for(con=0;con<rep;con++)  {
  168.          ActPunto(Xini+zx++,Yini+zy,ch);
  169.          if(zx>x)  {
  170.             zy++,zx=0;
  171.          } // end if
  172.          if (zy>y)  goto end;
  173.       }// end for
  174.       rep=1;
  175.    }// end while
  176. end: 
  177.    fclose(fp);
  178.    return(TRUE);
  179. }// end PonfPCX
  180.  
  181. /*
  182. main(int argc, char *argv[])
  183. {
  184.    pcx256 dibujo;
  185.    int x=4,y;
  186.  
  187.    modo320200();
  188.    InitMouse(0xFF);
  189.    show_mouse();
  190.    ide_mouse();
  191.    PonfPCX("dibujo.pcx",0,0);
  192.    if (argc ==2)  {
  193.       LeePCX(&dibujo,argv[1]);
  194.       while((estado & BUTTON_LEFT)==0)  {
  195.      x=mousex;
  196.      y=mousey;
  197.          PonmaskPCX(&dibujo,x,y,255);
  198.       }// end while
  199.    }// end if
  200.    return(0);
  201. }
  202. */
  203. #endif
  204.  
  205.  
  206.